<?php
	session_start();
	if(!array_key_exists("role", $_SESSION) || $_SESSION['role'] != "admin"){
		header("Location: /index.php");
		exit;
	}
	
	$conn = mysql_connect("", "piedu_user", "q&&^%@8ezO8+");
	mysql_select_db("piedu_db");
	
	$sql = "select * from promotions";
	$query = mysql_query($sql, $conn);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pie Education | Promotions</title>
<Meta name="Author" content="Rob Keller">
<Meta name="Publisher" content="Aaron Aceves">
<Meta name="Robots" content="NOINDEX,NOFOLLOW">
<Meta name="Content-Language" content="English">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="../css/style.css" />
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="80" bgcolor="#FF8C00" align="center"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><a href="index.php"><img src="../images/logo.png" alt="Return to Index" width="250" height="70" border="0" title="pie.edu an E-Learning Network" /></a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#000000" align="center"><a href="index.php" class="global-nav-menu" style="color:#FFF">Home </a><a href="coupons.php" class="global-nav-menu" style="color:#FFF">Manage Coupons </a><a href="promotions.php" class="global-nav-menu" style="color:#FFF">Manage Promotions </a><a href="items.php" class="global-nav-menu" style="color:#FFF">Manage Items</a><a href="manage_orders.php" class="global-nav-menu" style="color:#FFF">Manage Orders</a><a href="transactions.php" class="global-nav-menu" style="color:#FFF">Transactions Details</a><a href="#" class="global-nav-menu" style="color:#FFF">Another Menu</a><a href="#" class="global-nav-menu" style="color:#FFF">Another Menu</a><a href="#" class="global-nav-menu" style="color:#FFF">Another Menu</a><a href="/logout.php" class="global-nav-menu" style="color:#FFF">Logout</a></td>
  </tr>
  <tr>
    <td height="500" bgcolor="#FFFFFF"><table width="980" border="0" align="center" cellpadding="4" cellspacing="2">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2" align="center"><a href="promotions_action.php?action=add" class="button blue" style="color:#FFF">Add a New Promotion</a></td>
        </tr>
      <tr>
        <td width="40%"><?php 
		if(array_key_exists("deleted", $_GET)) {
			 echo '<div style="color:#F00"><strong>The promotion as been deleted</strong></div>'; 
		} else if(array_key_exists("added", $_GET)) {
			echo '<div style="color:#F00"><strong>The promotion as been added</strong></div>'; 
		} else if(array_key_exists("updated", $_GET)) {
			echo '<div style="color:#F00"><strong>The promotion as been updated successfully</strong></div>'; 
		} else if(array_key_exists("notfound", $_GET)) {
			echo '<div style="color:#F00"><strong>The selected promotion doesn\'t exist, please verify</strong></div>'; 
		}
		?></td>
        <td width="15%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        </tr>
      <tr>
        <td bgcolor="#000000" style="color:#FFF"><strong>Promotion Name</strong></td>
        <td bgcolor="#000000" style="color:#FFF" align="center"><strong>Start Date</strong></td>
        <td align="center" bgcolor="#000000" style="color:#FFF"><strong>End Date</strong></td>
        <td width="15%" align="center" bgcolor="#000000" style="color:#FFF"><strong>Discount Amount</strong></td>
        <td width="15%" align="center" bgcolor="#000000" style="color:#FFF"><strong>Delete Promotion</strong></td>
        </tr>
        
        <?php
		$counter = 1;
		while($data = mysql_fetch_assoc($query)){
			if($counter % 2){
				$color = "f4f4f4";
			} else {
				$color = "ffffff";
			}
      echo '<tr bgcolor="#'.$color.'">
        <td><a href="promotions_action.php?action=edit&id='.$data['id'].'" class="global-nav-menu" style="color:#00F">'.$data['code'].'</a></td>
        <td align="center">'.$data['start_date'].'</td>
        <td align="center">'.$data['end_date'].'</td>
        <td align="center">'.$data['discount_amount'].' '.$data['discount_type'].'</td>
        <td align="center"><a href="promotions_action.php?action=delete&id='.$data['id'].'" class="global-nav-menu" style="color:#00F">Delete</a></td>
        </tr>';
		$counter++;
		}
       ?>
       <tr>
        <td width="40%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        <td width="15%">&nbsp;</td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2" align="center"><a href="promotions_action.php?action=add" class="button blue" style="color:#FFF">Add a New Promotion</a></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td height="80" bgcolor="#FF9933" align="center"><a href="../index.php" class="bottom-general-menu" style="color:#FFF">Home</a> <a href="../platform.php" class="bottom-general-menu" style="color:#FFF">Platform</a> <a href="../piephone.php" class="bottom-general-menu" style="color:#FFF">Pie Phone</a> <a href="../company_training.php" class="bottom-general-menu" style="color:#FFF">Company Training</a> <a href="../jobs.php" class="bottom-general-menu" style="color:#FFF">Jobs</a> <a href="../press.php" class="bottom-general-menu" style="color:#FFF">Press</a> <a href="../community/" class="bottom-general-menu" style="color:#FFF">Community</a> <a href="../mobile.php" class="bottom-general-menu" style="color:#FFF">Mobile</a> <a href="support/" class="bottom-general-menu" style="color:#FFF">Help</a> <a href="../blog/" class="bottom-general-menu" style="color:#FFF">Blogs</a> <a href="../forums/" class="bottom-general-menu" style="color:#FFF">Forums</a><a href="../about.php" class="bottom-general-menu" style="color:#FFF">About</a> <a href="../terms.html" class="bottom-general-menu" style="color:#FFF">Terms of Use</a> <a href="../privacy.html" class="bottom-general-menu" style="color:#FFF">Privacy Policy</a> <a href="../contact-us.php" class="bottom-general-menu" style="color:#FFF">Contact Us</a></td>
  </tr>
</table>
</body>
</html>
